//
//  LSSetNickNameVController.m
//  LookScore
//
//  Created by wr on 2017/12/7.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSSetNickNameVController.h"
#import "LSAccountArchive.h"
#import "MBProgressHUD+MJ.h"
#import "LSHttpEnclosureTool.h"
#import "NSString+JKNormalRegex.h"
@interface LSSetNickNameVController ()<UITextFieldDelegate>

@property(strong,nonatomic)UITextField *inputTF;//输入框输入

@property(strong,nonatomic)UIView *lineView;//分割线


@end

@implementation LSSetNickNameVController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor=LSTitleWhiteColor;
   
    [self initWithUI:self.type];
}

-(void)initWithUI:(KRevampOrSetNickNameType )type{
  

    if (type==KRevampOrSetNickNameIsRevamp) {
        
        self.title=@"修改昵称";
        UITextField *inputTF=[[UITextField alloc]init];
        inputTF.font=LSFontSize13;
        inputTF.returnKeyType=UIReturnKeyDefault;
        inputTF.textColor=LSTitleGrayColor1;
        inputTF.delegate=self;
        
        [self.view addSubview:inputTF];
        self.inputTF=inputTF;
        inputTF.sd_layout.leftEqualToView(self.view).offset(LSSpaceLeftWidth2).topEqualToView(self.view).offset(11).rightEqualToView(self.view).offset(-LSSpaceLeftWidth2).heightIs(LSControlHeight);
        
        UIView *lineView=[[UIView alloc]init];
        lineView.backgroundColor=LSLineGrayColor;
        [self.view addSubview:lineView];
        self.lineView=lineView;
        lineView.sd_layout.leftEqualToView(self.view).offset(LSSpaceLeftWidth2).topSpaceToView(inputTF, 0).rightEqualToView(self.view).offset(-LSSpaceLeftWidth2).heightIs(.5f);
        
        UILabel *hintLab=[[UILabel alloc]init];
        hintLab.font=LSFontSize13;
        hintLab.textColor=LSTitleGrayColor2;
        [self.view addSubview:hintLab];
        hintLab.sd_layout.leftEqualToView(self.view).offset(LSSpaceLeftWidth2).topSpaceToView(lineView, 10).rightEqualToView(self.view).offset(-LSSpaceLeftWidth2).heightIs(20.f);
        
        UIButton *sureBu=[UIButton new];
        sureBu.layer.cornerRadius=5;
        sureBu.layer.masksToBounds=YES;
        
        [sureBu setBackgroundImage:[CommonClass getImageWithBgColor:LSNavMainColor] forState:UIControlStateHighlighted];
        [sureBu setBackgroundImage:[CommonClass getImageWithBgColor:LSSubColor7ec5fd] forState:UIControlStateNormal];
        [sureBu setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        sureBu.titleLabel.font=LSFontSize15;
        [sureBu addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:sureBu];
        sureBu.sd_layout.leftEqualToView(self.view).offset(LSSpaceLeftWidth2).topSpaceToView(hintLab, 39).rightEqualToView(self.view).offset(-LSSpaceLeftWidth2).heightIs(LSButtonHeight);
  
      self.inputTF.placeholder=@"请输入新昵称";
        hintLab.text=@"温馨提示 : 昵称只能修改一次哦！";
        [sureBu setTitle:@"确定修改" forState:UIControlStateNormal];
    }else if(type==KRevampOrSetNickNameIsSetting){
         self.title=@"设置昵称";
        
        UIImageView *inputImg=[[UIImageView alloc]init];
        inputImg.image=[UIImage imageNamed:@"MineNickName"];
        [self.view addSubview:inputImg];
        inputImg.sd_layout.leftEqualToView(self.view).offset(LSSpaceLeftWidth2+10).topEqualToView(self.view).offset(11).widthIs(15).heightIs(20);
        
        UITextField *inputTF=[[UITextField alloc]init];
        inputTF.font=LSFontSize13;
        inputTF.returnKeyType=UIReturnKeyDefault;
        inputTF.textColor=LSTitleGrayColor1;
        inputTF.delegate=self;
        
        [self.view addSubview:inputTF];
        self.inputTF=inputTF;
        inputTF.sd_layout.leftSpaceToView(inputImg, 10).centerYEqualToView(inputImg).rightEqualToView(self.view).offset(-LSSpaceLeftWidth2).heightIs(LSControlHeight);
        
        UIView *lineView=[[UIView alloc]init];
        lineView.backgroundColor=LSLineGrayColor;
        [self.view addSubview:lineView];
        self.lineView=lineView;
        lineView.sd_layout.leftEqualToView(self.view).offset(LSSpaceLeftWidth2).topSpaceToView(inputTF, 0).rightEqualToView(self.view).offset(-LSSpaceLeftWidth2).heightIs(.5f);
        
        UILabel *hintLab=[[UILabel alloc]init];
        hintLab.font=LSFontSize13;
        hintLab.textColor=LSTitleGrayColor2;
        hintLab.numberOfLines=2;
        [self.view addSubview:hintLab];
        hintLab.sd_layout.leftEqualToView(self.view).offset(LSSpaceLeftWidth2).topSpaceToView(lineView, 10).rightEqualToView(self.view).offset(-LSSpaceLeftWidth2).autoHeightRatio(0);
        
        UIButton *sureBu=[UIButton new];
        sureBu.layer.cornerRadius=5;
        sureBu.layer.masksToBounds=YES;
        
        [sureBu setBackgroundImage:[CommonClass getImageWithBgColor:LSNavMainColor] forState:UIControlStateHighlighted];
        [sureBu setBackgroundImage:[CommonClass getImageWithBgColor:LSSubColor7ec5fd] forState:UIControlStateNormal];
        [sureBu setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        sureBu.titleLabel.font=LSFontSize15;
        [sureBu addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:sureBu];
        sureBu.sd_layout.leftEqualToView(self.view).offset(LSSpaceLeftWidth2).topSpaceToView(hintLab, 39).rightEqualToView(self.view).offset(-LSSpaceLeftWidth2).heightIs(LSButtonHeight);
        
        UIButton *futureSetBu=[UIButton new];
        [futureSetBu setTitle:@"我要以后设置" forState:UIControlStateNormal];
        [futureSetBu setTitleColor:LSSubColor7ec5fd forState:UIControlStateNormal];
        futureSetBu.titleLabel.font=LSFontSize13;
        futureSetBu.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
        [futureSetBu addTarget:self action:@selector(futureSetNickAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:futureSetBu];
        futureSetBu.sd_layout.rightEqualToView(self.view).offset(-LSSpaceLeftWidth2).topSpaceToView(sureBu, 13).heightIs(20);
       
        self.inputTF.placeholder=@"请输入昵称";
        hintLab.text=@"温馨提示 : 昵称仅用于平台展示，不用于登录！";
        [sureBu setTitle:@"确定" forState:UIControlStateNormal];
    }
   
}
#pragma mark 🔥 确定事件
-(void)sureAction:(UIButton *)sender{
//    if (self.type==KRevampOrSetNickNameIsSetting) {
//
//    }else if (self.type==KRevampOrSetNickNameIsRevamp){
//
//    }
    if ([CommonClass isBlankString:self.inputTF.text]) {
        [MBProgressHUD showOnlyMessage:@"昵称不能为空" afterDelay:1.5f];
        return;
    }
    if ([CommonClass stringContrainsEmoji:self.inputTF.text]) {
        [MBProgressHUD showOnlyMessage:@"昵称不能含有表情符号" afterDelay:1.5f];
        return;
    }
//    if ([self.inputTF.text jk_isPureNumber]) {
//        [MBProgressHUD showOnlyMessage:@"昵称不能全部为数字" afterDelay:1.5f];
//    }
    else if(self.inputTF.text.length<2||self.inputTF.text.length>8){
        [MBProgressHUD showOnlyMessage:@"昵称需输入2-8个字符" afterDelay:1.5f];
    }else{
        NSDictionary *nameDic=@{@"cid":self.cid,@"disName":self.inputTF.text};
        [LSHttpEnclosureTool POST:LSUserChangename parameters:nameDic resBlock:^(id responseObject) {
            if (responseObject) {
                
                LSAccountCoder *coderModel = [LSAccountArchive account];
                coderModel.DisplayName=responseObject;
                [LSAccountArchive saveAccount:coderModel];
                
                if (self.PersonalDataChangedBlock) {
                    self.PersonalDataChangedBlock();
                }
                if(self.type==KRevampOrSetNickNameIsRevamp){
                    
                    LSAccountCoder *coderModel = [LSAccountArchive account];
                    coderModel.ModifyDisplayNameCount=0;
                    [LSAccountArchive saveAccount:coderModel];
                    [self.navigationController popViewControllerAnimated:YES];
                }
                else{
                    LSAccountCoder *coderModel = [LSAccountArchive account];
                    coderModel.ModifyDisplayNameCount=1;
                    [LSAccountArchive saveAccount:coderModel];
                    [self.navigationController popToRootViewControllerAnimated:YES];
                }
            }
        }];
    }
}

-(void)futureSetNickAction:(UIButton *)sender{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
